<?php
class ExtHtml {
	const RENDER_ARRAY	= 0x000001;
	const RENDER_STRING	= 0x000002;
	const RENDER_OBJECTS	= 0x000004;

	/**
	 * attempt to render an ExtEvent's data
	 *
	 * @todo think about the API design, this is not fixed in stone
	 */
	static function renderExtEvent(ExtEvent $ev,$mask=NULL) {
		if(NULL === $mask) {
			$mask = self::RENDER_ARRAY|self::RENDER_STRING|self::RENDER_OBJECTS;
		}
		if(is_array($ev->data) && $mask & self::RENDER_ARRAY) {
			foreach($ev->data as $src => $item) {
				if(is_subclass_of($item,'CPortlet') && $mask & self::RENDER_OBJECTS) {
					//TODO: render
				}
				elseif(is_string($item) && $mask & self::RENDER_STRING) {
					echo $item;
				}
				else {
					throw new Exception("Unknown type of sidebar item from '$src'");
				}
			}
		}
		elseif(is_string($ev->data) && $mask & self::RENDER_STRING) {
			echo $ev->data;
		}
		else {
			throw new Exception('Unallowed type of data in event');
		}
	}
}
